ass Solution {
public:
    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
        if (nums1.size() > nums2.size())
            swap(nums1, nums2);
        int m = nums1.size();
        int n = nums2.size();
        int left = 0, right = m;
        while (left <= right) {
            int i = left + (right - left) / 2;
            int j = (m + n + 1) / 2 - i;

            // 设置边界条件
            int left1Line = (i == 0) ? INT_MIN : nums1[i - 1];
            int right1Line = (i == m) ? INT_MAX : nums1[i];
            int left2Line = (j == 0) ? INT_MIN : nums2[j - 1];
            int right2Line = (j == n) ? INT_MAX : nums2[j];
            if (left1Line <= right2Line && left2Line <= right1Line) {
                if ((m + n) % 2 == 1) {
                    return max(left1Line, left2Line);
                }
                return (max(left1Line, left2Line) +
                        min(right1Line, right2Line)) /
                       2.0;
            } else if (left1Line > right2Line) {
                right = i - 1;
            } else {
                left = i + 1;
            }
        }

        return 0;
    }
};
